/*
 * This file is part of FinVis.
 *
 * FinVis is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * FinVis is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with FinVis.  If not, see <http://www.gnu.org/licenses/>
 *
 * @author Stephen Rudolph
 */

#include "FinViewKey.h"

#include <QCheckBox>
#include <QListWidget>
#include <QMessageBox>

FinViewKey::FinViewKey(QWidget *parent) : QDockWidget(parent)
{
    keyListWidget = new QListWidget;

    //Gradient
    QListWidgetItem *gradient = new QListWidgetItem(keyListWidget);
    //gradient->setFlags(gradient->flags() | Qt::ItemIsUserCheckable);
    gradient->setText(tr("Risk Gradient"));
    gradient->setIcon(QIcon(":/gradient.png"));
    //gradient->setCheckState(Qt::Checked);
    keyListWidget->addItem(gradient);

    //Selected investment
    QListWidgetItem *selectedInvestment = new QListWidgetItem(keyListWidget);
    //selectedInvestment->setFlags(gradient->flags() | Qt::ItemIsUserCheckable);
    selectedInvestment->setText(tr("Selected Investment"));
    selectedInvestment->setIcon(QIcon(":/selected_investment.png"));
    //selectedInvestment->setCheckState(Qt::Checked);
    keyListWidget->addItem(selectedInvestment);

    //Unselected investment
    QListWidgetItem *unselectedInvestment = new QListWidgetItem(keyListWidget);
    //unselectedInvestment->setFlags(gradient->flags() | Qt::ItemIsUserCheckable);
    unselectedInvestment->setText(tr("Unselected Investment"));
    unselectedInvestment->setIcon(QIcon(":/unselected_investment.png"));
    //unselectedInvestment->setCheckState(Qt::Checked);
    keyListWidget->addItem(unselectedInvestment);

    //Available funds
    QListWidgetItem *liquid = new QListWidgetItem(keyListWidget);
    //liquid->setFlags(gradient->flags() | Qt::ItemIsUserCheckable);
    liquid->setText(tr("Available Funds"));
    liquid->setIcon(QIcon(":/liquid.png"));
    //liquid->setCheckState(Qt::Checked);
    keyListWidget->addItem(liquid);

    //Investment boundary
    QListWidgetItem *boundary = new QListWidgetItem(keyListWidget);
    //boundary->setFlags(gradient->flags() | Qt::ItemIsUserCheckable);
    boundary->setText(tr("Investment Boundary"));
    boundary->setIcon(QIcon(":/boundary.png"));
    //boundary->setCheckState(Qt::Checked);
    keyListWidget->addItem(boundary);

    //Result
    QListWidgetItem *result = new QListWidgetItem(keyListWidget);
    //result->setFlags(gradient->flags() | Qt::ItemIsUserCheckable);
    result->setText(tr("Result"));
    result->setIcon(QIcon(":/result.png"));
    //result->setCheckState(Qt::Checked);
    keyListWidget->addItem(result);

    connect(keyListWidget, SIGNAL(itemChanged(QListWidgetItem*)),
            this, SLOT(itemChanged(QListWidgetItem*)));

    this->setWidget(keyListWidget);
    this->setWindowTitle(tr("Symbol Key"));
}

void FinViewKey::itemChanged(QListWidgetItem *item)
{
    enum::symbols symbol;

    if (item->text().compare("Risk Gradient") == 0)
    {
        symbol = SymbolGradient;
    }
    else if (item->text().compare("Selected Investment") == 0)
    {
        symbol = SymbolSelected;
    }
    else if (item->text().compare("Unselected Investment") == 0)
    {
        symbol = SymbolUnselected;
    }
    else if (item->text().compare("Available Funds") == 0)
    {
        symbol = SymbolLiquidAssets;
    }
    else if (item->text().compare("Investment Boundary") == 0)
    {
        symbol = SymbolBoundary;
    }
    else if (item->text().compare("Result") == 0)
    {
        symbol = SymbolResult;
    }
    else
    {
        QMessageBox *showSampleResult = new QMessageBox(QMessageBox::Information, "Scenario", tr("\nScenario: ") + item->text(), QMessageBox::Ok);
        showSampleResult->exec();
        symbol = SymbolGradient;
    }

    if (item->checkState() == Qt::Checked)
    {
        emit symbolEnabled(symbol);
    }
    else if (item->checkState() == Qt::Unchecked)
    {
        emit symbolDisabled(symbol);
    }
}

